package com.orphan.supplier.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.orphan.supplier.po.RealSupplier;
import com.orphan.supplier.service.ISupplierService;
import com.orphan.supplier.service.MqClientService;
import com.orphan.util.dto.SupplierFreezeDto;
import com.orphan.util.dto.SupplierInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jack
 * @since 2021-07-20
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {
     @Autowired
    ISupplierService iSupplierService;
     @GetMapping("getAll")
     public List<RealSupplier> getAll(){
         return iSupplierService.getAll();
     }
     @Scheduled(cron = "0/2 * * * * ?")
     @GetMapping("insert")
    public int insert(){
         List<RealSupplier> list =new ArrayList<>();
          if(MqClientService.arrayList.size()==0){
              return 0;
          }
         for(int i=0;i<MqClientService.arrayList.size();i++){
             RealSupplier realSupplier = new RealSupplier();
             SupplierInfoDto supplierInfoDto =MqClientService.arrayList.get(0);
             realSupplier.setUsername(supplierInfoDto.getUsername());
             realSupplier.setPassword(supplierInfoDto.getPassword());
             realSupplier.setGender(supplierInfoDto.getGender());
             realSupplier.setTel(supplierInfoDto.getTel());
             realSupplier.setIdPic(supplierInfoDto.getIdPic());
             realSupplier.setBrand(supplierInfoDto.getBrand());
             realSupplier.setLicensePic(supplierInfoDto.getLicensePic());
             realSupplier.setRanks(supplierInfoDto.getRank());
             realSupplier.setStatus(supplierInfoDto.getStatus());
             iSupplierService.insert(realSupplier);
             MqClientService.arrayList.remove(0);
         }


         return 1;
     }
    @GetMapping("findByItem")
    public Object findAll(int pageNO){
        return iSupplierService.findByItem(pageNO);
    }
    @GetMapping("check/{username}/{password}")
    public String check(@PathVariable("username") String username,@PathVariable("password") String password){
        if(password.equals(iSupplierService.check(username))){
            return "ok";
        }else {
            return "no";
        }
    }
}
